package algebra.rewriting.transform;

import algebra.op.AlgebraicOP;
import algebra.op.JoinOP;
import algebra.rewriting.RewriteRule;

public class CommutativeIntersection extends RewriteRule {

	private final AlgebraicOP op;

	public CommutativeIntersection(AlgebraicOP op) {
		this.op = op;
	}

	@Override
	public AlgebraicOP rewrite() {
		if (this.op instanceof JoinOP) {
			JoinOP ip = (JoinOP) op;
			return new JoinOP(ip.getSecondSubQuery(), ip.getFirstSubQuery());
		}
		return null;
	}

	@Override
	public boolean applicable() {
		return this.op instanceof JoinOP;
	}

}
